@include('admin.public.head')

<div class="ibox-title">
    <h5>公告消息</h5>
</div>

<div class="ibox-content">
    <form  class="form-horizontal">

        <div class="form-group">
            <label class="col-sm-3 control-label">公告标题：</label>
            <div class="col-sm-8">
                <input type="text" name="message_title" class="form-control" placeholder="公告标题"
                       value="{{$result->message_title??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">公告内容：</label>
            <div class="col-sm-8">
                <script id="meesage_content" name="meesage_content" type="text/plain" style="height:300px;">{!! $result->meesage_content??'' !!}</script>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">是否开启：</label>
            <div class="col-sm-9">
                <label value="1">
                    <input type="radio" name="is_open" value="1" @if(isset($result->id)) @if($result->is_open == '1') checked="checked" @endif @endif>开启
                </label>
                <label value="0">
                    <input type="radio" name="is_open" value="-1" @if(isset($result->id)) @if($result->is_open == '-1') checked="checked" @endif @else checked="checked" @endif>关闭
                </label>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <div class="col-sm-4 col-sm-offset-3">
                <input type="hidden" name="id" value="{{$result->id??''}}">
                <button class="btn btn-primary do" type="submit">操作</button>
            </div>
        </div>

    </form>
</div>

<script>
    var meesage_content = UE.getEditor('meesage_content');


    $('.do').click(function(){
        var form = new FormData();

        var message_title = $('input[name="message_title"]').val();
        var id = $('input[name="id"]').val();
        var is_open = $('input[name="is_open"]:checked').val();
        var meesage_content_content = meesage_content.getContent();

        form.append("message_title", message_title);
        form.append("id", id);
        form.append("is_open", is_open);
        form.append("meesage_content", meesage_content_content);

        $.ajax({
            type: 'POST',
            url: '/system_message' ,
            dataType:"json",   //返回格式为json
            data: form ,
            processData: false,
            contentType: false,
            success:function(data){

                if(data.status == '1') {
                    var swal_json = {
                        title: data.message,
                        type: "success"
                    }

                    swal(swal_json, function (isConfirm) {
                        window.location.reload();
                    });

                }else{
                    var swal_json = {
                        title: data.message,
                        type: "error"
                    }

                    swal(swal_json, function (isConfirm) {

                    });
                }
            }
        });

        return false;
    });
</script>

